package com.unicom.microserv.contest.contest18_web.param;


import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;

    public class Param extends HashMap
    {
        private static final long serialVersionUID = 1L;

        public Object get(String name)
        {
            return super.get(name);
        }

        public Object get(String name, Object def)
        {
            Object value = get(name);
            return (Object) (value == null ? def : value);
        }

        public String[] getNames()
        {
            String[] names = (String[])(String[])keySet().toArray(new String[0]);
            Arrays.sort(names);
            return names;
        }

        public String getString(String name)
        {
            Object value = get(name);
            return value == null ? null : value.toString();
        }

        public String getString(String name, String defaultValue)
        {
            return get(name, defaultValue).toString();
        }

        public int getInt(String name)
        {
            return getInt(name, 0);
        }

        public int getInt(String name, int defaultValue)
        {
            String value = getString(name, "");
            return "".equals(value) ? defaultValue : Integer.parseInt(value);
        }

        public double getDouble(String name)
        {
            return getDouble(name, 0.0D);
        }

        public double getDouble(String name, double defaultValue)
        {
            String value = getString(name, "");
            return "".equals(value) ? defaultValue : Double.parseDouble(value);
        }

        public boolean getBoolean(String name)
        {
            return getBoolean(name, false);
        }

        public boolean getBoolean(String name, boolean defaultValue)
        {
            String value = getString(name, "");
            return "".equals(value) ? defaultValue : Boolean.valueOf(value).booleanValue();
        }

        public BigDecimal getBigDecimal(String name)
        {
            return getBigDecimal(name, null);
        }

        public BigDecimal getBigDecimal(String name, BigDecimal defaultValue)
        {
            String value = getString(name, "");
            return "".equals(value) ? defaultValue : new BigDecimal(value);
        }
    }